package com.ts.notice;

import lombok.Data;

public class TheadDem02 {

    public static void main(String[] args) {

        User user = new User();
//        user.setName("admin");

        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                user.action();
            }, "线程-" + i).start();
        }
    }
}

@Data
class User {
    private ThreadLocal<String> threadLocal = new ThreadLocal<>();

    public void action() {
//        String temp = Thread.currentThread().getName();
//        this.name = Thread.currentThread().getName();
        threadLocal.set(Thread.currentThread().getName());
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + " -- " + threadLocal.get());
    }
}
